package com.yummy.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yummy.dto.QueryCategoryVo;
import com.yummy.entity.Category;
import com.yummy.entity.Employee;
import com.yummy.mapper.CategoryMapper;
import com.yummy.service.CategoryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author buding
 */
@Service
public class CategoryServiceImpl implements CategoryService {
    @Autowired
    CategoryMapper categoryMapper;

    Logger logger = LoggerFactory.getLogger(CategoryServiceImpl.class);
    @Override
    public PageInfo<Category> findAllCategory(QueryCategoryVo queryCategoryVo) {
        Page<Category> page = PageHelper.startPage(queryCategoryVo.getCurrentPage(), queryCategoryVo.getPageSize());
        logger.info(queryCategoryVo.toString());
        List<Category> Categorys = categoryMapper.selectAllCategoryBuCondition(queryCategoryVo);
        PageInfo<Category> pageInfo = page.toPageInfo();

        return pageInfo;
    }

    @Override
    public boolean editCategory(Category category) {
        return categoryMapper.updateByCategory(category)>0;
    }

    @Override
    public boolean addCategoryDish(Category category) {
        return categoryMapper.insertCategoryDish(category)>0;
    }

    @Override
    public boolean removeCategorys(String... ids) {
        return categoryMapper.delCategoryByIds(ids)>0;
    }

    @Override
    public Category findCategoryById(String id) {
        Category category = categoryMapper.selectCategoryById(id);
        return category;
    }

    @Override
    public List<Category> findCategoryByStore(Integer storeId) {

        return categoryMapper.selectByStoreId(storeId);
    }

    @Override
    public List<Category> findAll() {
        return categoryMapper.selectAll();
    }
}
